package com.apexsoft.test;

import com.apexsoft.aas.util.DefaultEncryptor;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.DefaultApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Author: initializr
 * @Description:
 * @Date: Created in 2019-10-23 13:43
 * @MODIFIED BY:
 */
@SpringBootApplication
@ComponentScan(basePackages = {"com.apexsoft.aas","com.apexsoft.test"})
public class SampleApplicationBoot {

    public static void main(String[] args) {
        ApplicationArguments arguments = new DefaultApplicationArguments(args);
        StringEncryptor jasypt = new DefaultEncryptor();
        if (arguments.containsOption("encrypt")) {
            System.out.println("----------------------------------------------------");
            for (String text : arguments.getNonOptionArgs()) {
                try {
                    System.out.println(text + ": ENC(" + jasypt.encrypt(text)+")");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }else if(arguments.containsOption("decrypt")) {
            System.out.println("----------------------------------------------------");
            for (String text : arguments.getNonOptionArgs()) {
                try {
                    System.out.println(text + ": " + jasypt.decrypt(text));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }else {
            SpringApplication.run(SampleApplicationBoot.class, args);
        }
    }
}
